<template>
  <div class="block_main blue-tit">
    <!-- <div class="nytit">首页&gt;通知/督办</div> -->

    <el-row style="padding-top: 10px">
      <el-col :span="24" style="padding:0 5px">
        <el-card>
          <div class="title">诉求</div>
          <el-form style="width:60%;" :rules="rules" ref="ruleForm" :model="AddForm" label-width="150px" size="small">
            <el-form-item label="企业名称" prop="company">
              <el-input v-model="AddForm.company" placeholder="请输入企业名称"></el-input>
            </el-form-item>
            <el-form-item label="企业联系人" prop="user">
              <el-input v-model="AddForm.user" placeholder="请输入联系人"></el-input>
            </el-form-item>
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="AddForm.phone" placeholder="请输入联系电话"></el-input>
            </el-form-item>
            <el-form-item label="详细地址">
              <el-input v-model="AddForm.title" placeholder="请输入详细地址"></el-input>
            </el-form-item>
            
            
          </el-form>
        </el-card>
      </el-col>
      
      <el-col :span="24" style="padding:0 5px;margin-top:30px;">
        <el-button size="small" type="success" @click="moveTo('ruleForm')">移交</el-button>
        <el-button size="small" type="primary" @click="saveForm('ruleForm')">保存</el-button>
        <el-button size="small" type="warning">取消</el-button>
      </el-col>
    </el-row>

  </div>
</template>
<script>
import actionurl from "@/assets/js/actionurl";
import selectMenu from "@/components/selectMenu.vue";
import config from "../../config";

export default {
  name: "questionAdd",
  components: {
    selectMenu
  },
  data() {
    return {
      overtime:'',
      httpHome: "",
      cityArr: [],
      countyArr: [],
      filePath: "",
      MsgGroup: [],
      sname: "市级部门",
      sname2: "县长热线",
      AddForm: {
        company: "",
        resource: "0",
        form:'0'
      },
      dynamicValidateForm: {
        domains: [
          {
            value: "运维",
            id: "10"
          }
        ],
        selectList: [
          {
            value: "",
            id: ""
          }
        ]
      },
      options: [
        {
          value: "10",
          label: "测试部门",
          id: "11"
        }
      ],
      dynamicValidateFormArea: {
        domains: [
          {
            value: "河北",
            id: "12"
          }
        ],
        selectList: [
          {
            value: "",
            id: ""
          }
        ]
      },
      optionsArea: [
        {
          value: "10",
          label: "安次区",
          id: "11"
        }
      ],

      fileList3: [],
      rules: {
        company: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
          { min: 2, message: "长度在2字符以上", trigger: "blur" }
        ],
        user: [
          { required: true, message: "请输入公司联系人", trigger: "blur" }
        ],
        phone: [{ required: true, message: "请输入联系电话", trigger: "blur" }]
      }
    };
  },
  created() {
    this.httpHome = config.URLWEBHTTP;
    //设置默认截止日期
      function addZero(n){
          return n<10?'0'+n:''+n
      }
      var ddd = new Date();

      var month=ddd.getMonth()+1;
      var day =  ddd.getDate()+7;
      var year = ddd.getFullYear();
      if(month==0){
        month=12;
        year=year-1;
      }
      if(month<10){
        month = addZero(month); 
      }
      this.overtime= year+"-"+month+"-"+day;
  },

  methods: {
    update(name) {
      //获取市级增加的菜单数组
      this.cityArr = name;
    },
    updateArea(name) {
      //获取区县级增加的菜单数组
      this.countyArr = name;
    },
    moveTo(formName) {
      this.loading = true;
      // return;
      var _this = this;
      _this.$refs[formName].validate(valid => {
        if (valid) {
          _this.loading = true;
          actionurl.MaddAndTransfer(
            {
              id: _this.$route.params.id,
              phone: _this.AddForm.phone,
              company: _this.AddForm.company,
              user: _this.AddForm.user,
              title: _this.AddForm.title,
              content: _this.AddForm.content,
              group: _this.AddForm.group,
              from: _this.AddForm.from,
              city:_this.$refs.mesage.getContent().join(','),
              county:_this.$refs.mesage2.getContent().join(','),
              attach:JSON.stringify(_this.fileList3),
              final_time:_this.overtime
            },
            function(re) {
              _this.$message("添加成功");
              _this.loading = false;
              _this.$router.push({ path: "/home" });
            }
          );
        } else {
          console.log("error submit!!");
          _this.loading = false;
          return false;
        }
      });
    },
    saveForm(formName) {
      //保存操作
      this.loading = true;
      // return;
      var _this = this;
      _this.$refs[formName].validate(valid => {
        if (valid) {
          _this.loading = true;
          actionurl.MuserAdd(
            {
              id: _this.$route.params.id,
              phone: _this.AddForm.phone,
              company: _this.AddForm.company,
              user: _this.AddForm.user,
              title: _this.AddForm.title,
              content: _this.AddForm.content,
              group: _this.AddForm.group,
              from: _this.AddForm.from,
              city:_this.$refs.mesage.getContent().join(','),
              county:_this.$refs.mesage2.getContent().join(','),
              attach:JSON.stringify(_this.fileList3),
              final_time:_this.overtime
            },
            function(re) {
              if(re.status == 1){
                _this.$message(re.msg);
                _this.loading = false;
                _this.$router.push({ path: "/home" });
              }else{
                _this.$message(re.msg);
                _this.loading = false;
               
              }
              
            }
          );
        } else {
          console.log("error submit!!");
          _this.loading = false;
          return false;
        }
      });
    },
    handleUpload(file, fileList) {
      // this.fileList3 = fileList.slice(-3);
    },
    beforeupload(file){
      
    },
    fileSuccess(event, file, fileList){
      console.log(file,'file');
      if(file.response.status=='0'){
        var obj={};
        obj.name = file.name;
        obj.url =  file.response.data.path
        this.fileList3.push(obj);
      }else{
        this.$message("添加失败");
        // console.log(this.fileList3,'fileList3');
        // this.fileList3.splice(this.fileList3.length-1,1);
      }
    },
    GetTargetList() {
      //获取区县以及市级下拉菜单获取
      var _this = this;
      actionurl.targetListByType({}, function(re) {
        _this.options = re.data.city;
        _this.optionsArea = re.data.county;
      });
    },
    GetMsgGroup() {
      //获取诉求分类
      var _this = this;
      actionurl.MessageGroup(
        {
          mesgroup: 1, //0-面对面等分类 1-八大类
          fid: 1
        },
        function(re) {
          console.log(re);
          _this.MsgGroup = re.data;
        }
      );
    },
    handlemove(file, fileList){
      console.log(file,'file')
      var _this = this;
        actionurl.delfile({
          file:file.url
        }, function(re) {
          if(re.status=1){
            _this.$message('删除成功');
            _this.fileList3 = fileList;
          }else{
            _this.$message(re.msg);
          }
      });
    },
  },
  mounted() {
    this.GetTargetList();
    this.GetMsgGroup();
    $(".selectinput")
      .find("input")
      .each(function() {
        var length = $(this).val().length;
        $(this).css("width", length * 15 + 40);
      });
  }
};
</script>
<style scoped lang="scss">
.btnflex {
  display: flex;
  position: relative;

  // .add{
  //   position: absolute;
  //   right: 0;
  //   top: 0;
  // }
  p {
    margin-right: 20px;
  }
}
.el-form--inline.selectinput .el-form-item {
  position: relative;
}
.el-form--inline.selectinput .el-form-item:after {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 20px 20px 0;
  border-color: transparent #f00 transparent transparent;
  position: absolute;
  right: 0;
  top: 1px;
  z-index: 1;
}
.el-form--inline.selectinput {
  padding-left: 20px;
}
.el-form--inline.selectinput .el-form-item .el-input__inner {
  text-align: center;
}
.el-form--inline.selectinput .el-form-item .el-icon-close {
  position: absolute;
  right: 0;
  top: 1px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  z-index: 2;
}
label {
  display: inline-block;
  text-align: right;
  padding: 0 12px 0 0;
}
</style>
